package com.itany.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.dao.ArticleTypeDao;
import com.itany.entity.ArticleType;
import com.itany.service.ArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author:yaozhiyuan0117@163.com
 * Time:2019/12/20 15:23
 * Describe:
 * version:1.0
 */

@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ArticleTypeServiceImpl implements ArticleTypeService {

    @Autowired
    private ArticleTypeDao articleTypeDao;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public PageInfo<ArticleType> findByPage(Integer page, Integer rows) {
        PageHelper.startPage(page,rows);
        List<ArticleType> types = articleTypeDao.selectByPage();
        PageInfo<ArticleType> info = new PageInfo(types);
        return info;
    }

    @Override
    public void addType(ArticleType type) {
        articleTypeDao.insertType(type);
    }

    @Override
    public List<ArticleType> findAll() {
        List<ArticleType> types = articleTypeDao.selectByPage();
        return types;
    }

    @Override
    public ArticleType findById(Integer id) {

        return articleTypeDao.selectById(id);

    }

    @Override
    public void modifyArticleType(ArticleType type) {
        articleTypeDao.updateType(type);
    }

}
